package cac.fenjian.resource.materialreceipt.util;

import cac.common.CallInterFace.service.CallInterfaceService;
import cac.fenjian.resource.materialreceipt.dao.PackageUnpackDao;
import cac.fenjian.resource.materialreceipt.service.MaterialReceiptService;
import cac.fenjian.resource.outBill.dao.WmsInvOutBillHDao;
import com.cac.dme.adapter.rest.msg.ResponseMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;

@Component
@Slf4j
public class PackageUnpackServiceUtil {

    @Autowired
    private WmsInvOutBillHDao wmsInvOutBillHDao;
    @Autowired
    private MaterialReceiptService materialReceiptService;
    @Autowired
    private CallInterfaceService callInterfaceService;
    @Autowired
    private PackageUnpackDao packageUnpackDao;

    /***
     * 取消占用以及重新占用
     * */
    @Async
    public void unpackAllot(HashMap map, String userCode, String IP) {
        //根据台账id查询占用信息
        List<HashMap> params = packageUnpackDao.queryUnpackCancelAllot(map);
        for(HashMap param : params){
            HashMap cancel = new HashMap();
            cancel.put("wmsInvOutAllotmentId",param.get("originalId").toString());
            cancel.put("opUserCode", userCode);
            cancel.put("IP",IP);
            cancel.put("cancelQty",param.get("applyQty"));
            //拆包取消
            String canceldata=materialReceiptService.sortOccupyCancle(cancel);
            callInterfaceService.sendBData("sendBData", "拆包取消", canceldata, "两网传输-发送业务数据");
            log.info("拆包取消信息上传完成");
        }
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //查询拆包占用信息
        //拆包占用
        List<HashMap> allotments = packageUnpackDao.queryUnpackAllotment(map);
        for(HashMap allotment : allotments){
            String parameters = materialReceiptService.sortOccupy(userCode, IP, allotment);
            callInterfaceService.sendBData("sendBData", "两网传输-发送业务数据", parameters, "拆包占用");
            log.info("拆包占用信息上传完成");
        }

    }
}
